﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SSN.Objects;
using SSN.DotNet;

namespace SSN.WebFramework
{
    public static class WebSettings
    {
        public static string AdministrationRole
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.AdminRole", "SSN IT");
            }
        }
        /// <summary>
        /// General name of the web application.
        /// </summary>
        public static string AppName
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.AppName", "SwfApp");
            }
        }

        /// <summary>
        /// Base url of the website.
        /// </summary>
        public static string SiteUrlBase
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.SiteUrl", ".");
            }
        }

        /// <summary>
        /// Required role for accessing the site.
        /// </summary>
        public static string RequiredRole
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.RequiredRole", "");
            }
        }

        /// <summary>
        /// Security type required to access the site (Windows vs Username/Password)
        /// </summary>
        public static WebLoginType SecurityType
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.SecurityType", "UserPass").ToEnum<WebLoginType>();
            }
        }

        /// <summary>
        /// Whether to encrypt the parameters.
        /// </summary>
        public static bool EncryptParameters
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.EncryptParameters", "false").ToBool();
            }
        }

        /// <summary>
        /// How to log page views.
        /// </summary>
        public static string LoggingType
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.LoggingType", "");
            }
        }

        /// <summary>
        /// If logging via file, this is the path to write the files to.
        /// </summary>
        public static string LoggingPath
        {
            get
            {
                var ret = ConfigManager.GetConfigSetting("Web.LoggingPath", ".");
                if (!ret.EndsWith(@"\"))
                    ret += @"\";
                return ret;
            }
        }

        /// <summary>
        /// Name of the file to write to for logging.
        /// </summary>
        public static string LoggingFile
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.LoggingFile", "swf_log.log");
            }
        }

        /// <summary>
        /// If logging to a database, the table to log to.
        /// </summary>
        public static string LoggingDbTable
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.LoggingDbTable", "fw_tracking");
            }
        }

        /// <summary>
        /// If logging to a database, the table to log the details to.
        /// </summary>
        public static string LoggingDbDetailsTable
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.LoggingDbDetailsTable", "fw_tracking_parameters");
            }
        }

        /// <summary>
        /// Default page to redirect to upon logging in.
        /// </summary>
        public static string DefaultPage
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.DefaultUrl", "~/Default.aspx");
            }
        }

        /// <summary>
        /// Page to redirect to when the password change is required.
        /// </summary>
        public static string ChangePasswordPage
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.PasswordChangeUrl", "~/change_pass.aspx?required=true");
            }
        }

        /// <summary>
        /// Page to redirect to when a log in is required.
        /// </summary>
        public static string LogInPage
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.LoginPage", "~/login.aspx");
            }
        }

        /// <summary>
        /// Page to redirect to when a log out occurs.
        /// </summary>
        public static string  LogOutPage
        {
            get
            {
                return ConfigManager.GetConfigSetting("Web.LogoutPage", "~/Logout.aspx");
            }
        }        

        /// <summary>
        /// Page to redirect to on unauthorized acccesses.
        /// </summary>
        public static string NotAuthorizedPage
        {
            get { return ConfigManager.GetConfigSetting("Web.NotAuthorizedPage", ""); }
        }

        /// <summary>
        /// Page to redirect to on errors.
        /// </summary>
        public static string ErrorPage
        {
            get { return ConfigManager.GetConfigSetting("Web.ErrorPage", ""); }
        }
    }
}
